<template>
	<uni-card :is-shadow="false">
		<text class="uni-h1">aLocSDK</text>
	</uni-card>
	<uni-card :is-shadow="false">
		<uni-section title="状态" type="line" padding>
			<uni-card :is-shadow="false" is-full>
				<text class="uni-h6">{{tvInfo}}</text>
			</uni-card>
		</uni-section>
		<button @click="btnStart" type="primary" class="uni-mt-2 uni-mx-2">开始</button>	
		<button @click="btnPause" type="primary" class="uni-mt-2 uni-mx-2">暂停</button>	
	</uni-card>
</template>

<script>
	export default {
		data() {
			return {
				tag:'Huo15AlocModule',
				huo15Sdk:null,
				tvInfo:'',
			}
		},
		onLoad() {
			this.huo15Sdk = uni.requireNativePlugin('Huo15-Aloc')
			this.huo15Sdk.initEngine()
			const globalEvent = uni.requireNativePlugin('globalEvent')
			globalEvent.addEventListener('huo15_notify', (e) => {
				console.log(this.tag,JSON.stringify(e));
				if(e.tv_info!==undefined){
					//x e.tv_info.x
					//y e.tv_info.y
					//....
					// 属性有x,y,lng,lat,floor_code,build_code,bearing,update_type,time_millis,format_debug_log
					this.tvInfo=e.tv_info
				}
				if(e.init_info!==undefined){
					uni.showToast({
						title:e.init_info,
						icon:'none'
					})
				}
			})
			
		},
		methods: {
			btnStart(){
				console.log(this.tag,'btnStart');
				this.huo15Sdk.startLocation({
					is_start:true
				})
			},
			btnPause(){
				console.log(this.tag,'btnPause');
				this.huo15Sdk.startLocation({
					is_start:false
				})
			},
		}
	}
</script>

<style>

</style>
